/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Dimensions,
  Image,
  AsyncStorage
} from 'react-native';

var _navigator;
var timer;

class Welcome extends Component {
	constructor(props) {  
		super(props);
		
		_navigator = this.props.navigator;
		
		this.state = { 
			waittime: 3,
			page: "first",
		};
		
	    // 每1000毫秒对showText状态做一次取反操作
	    timer = setInterval(() => {
	    	var time = this.state.waittime;
	    	time--;
	      	this.setState({waittime:time});
	      	if(time === 0){
	      		clearInterval(timer);
	      		_navigator.resetTo({id:this.state.page});
	      	}
	    }, 1000);
  	} 
	
	componentDidMount() {
		_this = this;
		AsyncStorage.getItem("user_id",function(errors,result){
			console.log(result);
			if(result == null)
				_this.setState({page:"Login"});
		});
	}
	
	componentWillUnmount(){
		clearInterval(timer);
	}
	
	render() {
	    return (
	      	<View style={styles.container}>
	      		<View style={[styles.border,{position:'absolute',right:25,top:30}]}>
		      		<Text style={{color:"#000000"}}>等待 {this.state.waittime}</Text>
		      	</View>
	      		<Image source={require('./../image/common/startPage.png')} style={styles.bgImage}>	 
		      		
	      		</Image>
	      		<View style={{flex:1}}></View>
	      		<Text style={{marginBottom:20}}>深圳威普科技智能科技有限公司</Text>
	      	</View>
	    );
	}
}
 
const styles = StyleSheet.create({
	container: {
	    flex: 1,
	    justifyContent: 'center',
	    alignItems: 'center',
	    backgroundColor: '#FAF4FF',
	},
	bgImage:{
		width:Dimensions.get('window').width-100, 
		height:Dimensions.get('window').height-100,
		resizeMode:'contain'
	},
	border:{
		width:60,
		height:20,
		borderColor:'black',
		borderWidth:1,
		borderRadius:40,
	    justifyContent: 'center',
	    alignItems: 'center',
	}
});

module.exports = Welcome;
